package com.plian.system.controller.fr.gsalayslip;

import com.plian.Tools.base.BaseController;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.annotation.Behavioral;
import com.plian.system.config.Resubmit;
import com.plian.system.model.CommonCode;
import com.plian.system.model.ListResult;
import com.plian.system.model.ObjResult;
import com.plian.system.model.R;
import com.plian.system.service.fr.gsalaryslip.GsalarySlipAdjustmentService;
import com.plian.system.service.fr.gsalaryslip.GsalarySlipService;
import com.plian.system.service.fr.report.IReportService;
import com.plian.system.service.fr.report.IReportTableConfigService;
import com.plian.system.vo.fr.report.ReportTableConfigVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "api/gsalarySlip")
public class GsalarySlipController extends BaseController {
    @Autowired
    GsalarySlipService gsalarySlipService;

    @Autowired
    GsalarySlipAdjustmentService gsalarySlipAdjustmentService;

    @Autowired
    IReportTableConfigService reportTableConfigService;

    @Autowired
    IReportService reportService;

    @PostMapping(value = "/savereport")
    @Resubmit(delaySeconds = 0)
    public ObjResult savereport(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.savereport(pd);
    }

//    @PostMapping(value = "/savezb") TODO DEL
//    @Resubmit(delaySeconds = 0)
//    public ObjResult savezb(@RequestBody PageData pd) throws Exception {
//        return gsalarySlipService.savezb(pd);
//    }

    @PostMapping(value = "/listpage")
    public ListResult<PageData> listpage(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.listPage(pd);
    }

    @PostMapping(value = "/treeList")
    public ListResult<PageData> treeList(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.treeList(pd);
    }

    @PostMapping(value = "/listTree")
    public ListResult<PageData> listTree(@RequestBody PageData pd) throws Exception {
        return gsalarySlipAdjustmentService.listPage(pd);
    }

    @PostMapping(value = "/adjustmentValuelist")
    public ListResult<PageData> adjustmentValuelist(@RequestBody PageData pd) throws Exception {
        return gsalarySlipAdjustmentService.valuelist(pd);
    }

    @PostMapping(value = "/alist")
    public List<PageData> alist(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.alist(pd);
    }

    @PostMapping(value = "/valuelist")
    public ListResult<PageData> valuelist(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.valuelist(pd);
    }

    /**
     * valuelist合起来作为接口信息
     *
     * @param pd
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/allValueList")
    public ListResult<PageData> allValueList(@RequestBody PageData pd) throws Exception {
        List<Map<String,Object>> result = reportService.getAllValue(pd.getString("year"), pd.getString("id"));
        ListResult listResult = new ListResult(CommonCode.SUCCESS);
        listResult.setList(result);
        listResult.setTotal(result.size());
        return listResult;
    }


    @PostMapping(value = "/detaillist")
    public ListResult<PageData> detaillist(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.detaillist(pd);
    }

    @PostMapping(value = "/uploadFile", produces = "application/json;charset=UTF-8")
    public ObjResult uploadFile(MultipartHttpServletRequest request) throws Exception {
        return gsalarySlipService.uploadFile(request);
    }

    @PostMapping(value = "/exportExcel", produces = "application/json;charset=UTF-8")
    public void exportExcel(@RequestBody PageData pd, HttpServletResponse response, OutputStream os) throws Exception {
        ArrayList<LinkedHashMap> list = (ArrayList<LinkedHashMap>) pd.get("data");
        gsalarySlipService.exportExcel(list, pd.getString("year"), response, os);
    }
//    @PostMapping(value = "/addvaluelist")
//    public ListResult<PageData> addvaluelist(@RequestBody PageData pd) throws Exception {
//        return gsalarySlipService.addvaluelist(pd);
//    }
//
//    @PostMapping(value = "/overvaluelist")
//    public ListResult<PageData> overvaluelist(@RequestBody PageData pd) throws Exception {
//        return gsalarySlipService.overvaluelist(pd);
//    }
//    @PostMapping(value = "/lastyear")
//    public ListResult<PageData> lastyear(@RequestBody PageData pd) throws Exception {
//        return gsalarySlipService.lastyear(pd);
//    }

    //    @PostMapping(value = "/editvalue")
//    public ObjResult editvalue(@RequestBody PageData pd) throws Exception {
//        return gsalarySlipService.editvalue(pd);
//    }
    @PostMapping(value = "/delete")
    public ObjResult delete(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.delete(pd);
    }

    @PostMapping(value = "/originReport")
    @Resubmit(delaySeconds = 0)
    public ObjResult originReport(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.originReport(pd);
    }

    @PostMapping(value = "/savefm")
    public ObjResult savefm(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.savefm(pd);
    }

    @PostMapping(value = "/saveChecked")
    public ObjResult saveChecked(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.saveChecked(pd);
    }

    @PostMapping(value = "/saveDiffChecked")
    public ObjResult saveDiffChecked(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.saveDiffChecked(pd);
    }

    @PostMapping(value = "/updatePassStatus")
    public ObjResult updatePassStatus(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.updatePassStatus(pd);
    }

    @PostMapping(value = "/findfm")
    @Behavioral(formType = "1",actionTypeId = "1")
    public ObjResult findfm(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.findfm(pd);
    }

    @PostMapping(value = "/findChecked")
    public ObjResult findChecked(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.findChecked(pd);
    }

    @PostMapping(value = "/findDiffChecked")
    public ObjResult findDiffChecked(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.findDiffChecked(pd);
    }

    @PostMapping(value = "/ishavedata")
    public ObjResult ishavedata(@RequestBody PageData pd) throws Exception {
        return gsalarySlipService.ishavedata(pd);
    }

    @GetMapping(value = "/getTableConfig")
    public R<ReportTableConfigVO> getTableConfig(String year) {
        R<ReportTableConfigVO> r = new R<>(CommonCode.SUCCESS);
        r.setPageData(reportTableConfigService.getTableConfig(year));
        return r;
    }

    @PostMapping(value = "/findAuthorizeValue")
    public ListResult<PageData> findAuthorizeValue(@RequestBody PageData pd) throws Exception {
        return reportService.findAuthorizeValue(pd);
    }

    /**
     * 消息测试
     *
     * @param pd
     * @throws Exception
     */
    @PostMapping(value = "/messageTest")
    public void messageTest(@RequestBody PageData pd) throws Exception {
        gsalarySlipService.messageTest(pd);
    }

}
